import { mapGetters, mapActions } from "vuex";
import XTable from "vux/src/components/x-table/index.vue";

import template from "./vipLevelTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  components: {
    XTable,
  },
  data() {
    return {
      nextName: "",
      userScore: 0,
      differScore: 0,
      nextStatus: 0,
      honor: [],
      bettingMoney: 0,
      bettingScore: 0,
      rechargeMoney: 0,
      rechargeScore: 0,
      winningMoney: 0,
      winningScore: 0,

      pullDownRefresh: true,
    };
  },
  created() {
    this._getHonorData(1);
    var vm = this;
    if (vm.userInfo.username) {
      setTimeout(function () {
        vm.integralData();
      }, 20);
    }
  },
  mounted() {},
  computed: {
    ...mapGetters(["userInfo", "accountData"]),
  },
  methods: {
    goToRecharge() {
      if (!JSON.parse(localStorage.getItem("isUser"))) {
        this.$vux.alert.show({
          content: "游客暂无权限，请先注册会员",
          buttonText: "知道了",
        });
      } else {
        this.$router.push({
          path: "/recharge",
        });
      }
    },
    integralData() {
      //当前等级数据
      var score = Number(this.userInfo.honor.score);
      var nextScore = Number(this.userInfo.honor.next_score);
      this.nextName = this.userInfo.honor.next_name;
      this.userScore = Number(this.userInfo.honor.user_score);
      this.differScore = nextScore - this.userScore;
      this.nextStatus = this.userInfo.honor.next_status;
    },
    _getHonorData(flag) {
      if (flag) {
        this.$vux.loading.show();
      }
      var honorData = {
        token: localStorage.getItem("token"),
      };
      this.$http
        .post(this.urlRequest + "?m=api&c=user&a=getHonor", honorData)
        .then((res) => {
          if (flag) {
            this.$vux.loading.hide();
          }
          if (res.status == 0) {
            this.honor = res.honor;
            this.bettingMoney = res.plus_score.betting.money;
            this.bettingScore = res.plus_score.betting.score;
            this.rechargeMoney = res.plus_score.recharge.money;
            this.rechargeScore = res.plus_score.recharge.score;
            this.winningMoney = res.plus_score.winning.money;
            this.winningScore = res.plus_score.winning.score;
          } else {
            if (res.ret_msg && res.ret_msg != "") {
              this.$vux.toast.show({
                text: res.ret_msg,
              });
            }
          }
        })
        .catch((error) => {
          this.$refs.scroll.forceUpdate(false);
          this.$vux.loading.hide();
          this.$vux.toast.show({
            text: "数据请求超时",
          });
        });
    },
    pullingDown() {
      this._getHonorData(0);
    },
  },
  watch: {
    userInfo(obj) {
      var vm = this;
      if (obj.username) {
        setTimeout(function () {
          vm.integralData();
        }, 20);
      }
    },
  },
};

// WEBPACK FOOTER //
// ./src/components/personalCenter/vipLevel/vipLevel.vue
